package com.mxw.commons.utils;

import cn.hutool.core.text.CharSequenceUtil;
import com.mxw.commons.context.ApplicationContextHelper;
import org.springframework.core.env.Environment;

import java.util.Arrays;

/**
 * @Description 判断环境变量的工具类
 * @Author RingKo
 * @Date 2022/8/1 16:06
 * @Version 1.0
 */
public class EnvironmentUtil {
  private EnvironmentUtil() {
  }

  public static boolean isDev() {
    Environment environment = ApplicationContextHelper.getEnvironment();
    return Arrays.stream(environment.getActiveProfiles())
        .anyMatch(env -> (CharSequenceUtil.equalsIgnoreCase(env, "dev")));
  }

  public static boolean isPrd() {
    Environment environment = ApplicationContextHelper.getEnvironment();
    return Arrays.stream(environment.getActiveProfiles())
        .anyMatch(env -> (CharSequenceUtil.equalsIgnoreCase(env, "prd")));
  }

  public static boolean isLocal() {
    Environment environment = ApplicationContextHelper.getEnvironment();
    return Arrays.stream(environment.getActiveProfiles())
        .anyMatch(env -> (CharSequenceUtil.startWithIgnoreCase(env, "local-")));
  }

  public static boolean isQa() {
    Environment environment = ApplicationContextHelper.getEnvironment();
    return Arrays.stream(environment.getActiveProfiles())
        .anyMatch(env -> (CharSequenceUtil.equalsIgnoreCase(env, "qa")));
  }
}
